﻿/****** Object:  ForeignKey [FK_Lit_Operario_Lit_Puesto]    Script Date: 03/24/2009 22:26:43 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Lit_Operario_Lit_Puesto]') AND type = 'F')
ALTER TABLE [dbo].[Lit_Operario] DROP CONSTRAINT [FK_Lit_Operario_Lit_Puesto]
GO
/****** Object:  ForeignKey [FK_Lit_RegistroOT_Lit_RegistroOT]    Script Date: 03/24/2009 22:26:45 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Lit_RegistroOT_Lit_RegistroOT]') AND type = 'F')
ALTER TABLE [dbo].[Lit_OrdenTrabajo] DROP CONSTRAINT [FK_Lit_RegistroOT_Lit_RegistroOT]
GO
/****** Object:  ForeignKey [FK_lit_registroOTDetalle_Lit_RegistroOT]    Script Date: 03/24/2009 22:26:50 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_registroOTDetalle_Lit_RegistroOT]') AND type = 'F')
ALTER TABLE [dbo].[Lit_OTDetalle] DROP CONSTRAINT [FK_lit_registroOTDetalle_Lit_RegistroOT]
GO
/****** Object:  ForeignKey [FK_Lit_OTGasto_Lit_Gasto]    Script Date: 03/24/2009 22:26:51 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Lit_OTGasto_Lit_Gasto]') AND type = 'F')
ALTER TABLE [dbo].[Lit_OTGasto] DROP CONSTRAINT [FK_Lit_OTGasto_Lit_Gasto]
GO
/****** Object:  ForeignKey [FK_Lit_OTGasto_Lit_OrdenTrabajo]    Script Date: 03/24/2009 22:26:52 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Lit_OTGasto_Lit_OrdenTrabajo]') AND type = 'F')
ALTER TABLE [dbo].[Lit_OTGasto] DROP CONSTRAINT [FK_Lit_OTGasto_Lit_OrdenTrabajo]
GO
/****** Object:  ForeignKey [FK_lit_privilegio_lit_aplicacion]    Script Date: 03/24/2009 22:26:57 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_privilegio_lit_aplicacion]') AND type = 'F')
ALTER TABLE [dbo].[lit_privilegio] DROP CONSTRAINT [FK_lit_privilegio_lit_aplicacion]
GO
/****** Object:  ForeignKey [FK_lit_privilegio_lit_privilegio]    Script Date: 03/24/2009 22:26:57 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_privilegio_lit_privilegio]') AND type = 'F')
ALTER TABLE [dbo].[lit_privilegio] DROP CONSTRAINT [FK_lit_privilegio_lit_privilegio]
GO
/****** Object:  ForeignKey [FK_lit_rol_lit_aplicacion]    Script Date: 03/24/2009 22:27:00 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_rol_lit_aplicacion]') AND type = 'F')
ALTER TABLE [dbo].[lit_rol] DROP CONSTRAINT [FK_lit_rol_lit_aplicacion]
GO
/****** Object:  ForeignKey [FK_lit_rol_privilegio_lit_privilegio]    Script Date: 03/24/2009 22:27:01 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_rol_privilegio_lit_privilegio]') AND type = 'F')
ALTER TABLE [dbo].[lit_rol_privilegio] DROP CONSTRAINT [FK_lit_rol_privilegio_lit_privilegio]
GO
/****** Object:  ForeignKey [FK_lit_rol_privilegio_lit_rol]    Script Date: 03/24/2009 22:27:01 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_rol_privilegio_lit_rol]') AND type = 'F')
ALTER TABLE [dbo].[lit_rol_privilegio] DROP CONSTRAINT [FK_lit_rol_privilegio_lit_rol]
GO
/****** Object:  ForeignKey [FK_lit_usuario_lit_aplicacion]    Script Date: 03/24/2009 22:27:03 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_usuario_lit_aplicacion]') AND type = 'F')
ALTER TABLE [dbo].[lit_usuario] DROP CONSTRAINT [FK_lit_usuario_lit_aplicacion]
GO
/****** Object:  ForeignKey [FK_lit_usuario_lit_usuario]    Script Date: 03/24/2009 22:27:03 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_usuario_lit_usuario]') AND type = 'F')
ALTER TABLE [dbo].[lit_usuario] DROP CONSTRAINT [FK_lit_usuario_lit_usuario]
GO
/****** Object:  ForeignKey [FK_lit_usuario_rol_lit_rol]    Script Date: 03/24/2009 22:27:04 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_usuario_rol_lit_rol]') AND type = 'F')
ALTER TABLE [dbo].[lit_usuario_rol] DROP CONSTRAINT [FK_lit_usuario_rol_lit_rol]
GO
/****** Object:  ForeignKey [FK_lit_usuario_rol_lit_usuario]    Script Date: 03/24/2009 22:27:04 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_usuario_rol_lit_usuario]') AND type = 'F')
ALTER TABLE [dbo].[lit_usuario_rol] DROP CONSTRAINT [FK_lit_usuario_rol_lit_usuario]
GO
/****** Object:  Table [dbo].[lit_usuario]    Script Date: 03/24/2009 22:27:02 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_usuario]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[lit_usuario]
GO
/****** Object:  Table [dbo].[lit_rol]    Script Date: 03/24/2009 22:27:00 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_rol]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[lit_rol]
GO
/****** Object:  Table [dbo].[lit_privilegio]    Script Date: 03/24/2009 22:26:57 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_privilegio]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[lit_privilegio]
GO
/****** Object:  Table [dbo].[Lit_OrdenTrabajo]    Script Date: 03/24/2009 22:26:45 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_OrdenTrabajo]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Lit_OrdenTrabajo]
GO
/****** Object:  Table [dbo].[Lit_Puesto]    Script Date: 03/24/2009 22:26:58 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_Puesto]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Lit_Puesto]
GO
/****** Object:  Table [dbo].[lit_aplicacion]    Script Date: 03/24/2009 22:26:39 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_aplicacion]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[lit_aplicacion]
GO
/****** Object:  Table [dbo].[lit_rol_privilegio]    Script Date: 03/24/2009 22:27:01 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_rol_privilegio]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[lit_rol_privilegio]
GO
/****** Object:  Table [dbo].[lit_usuario_rol]    Script Date: 03/24/2009 22:27:03 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_usuario_rol]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[lit_usuario_rol]
GO
/****** Object:  Table [dbo].[Lit_OTGasto]    Script Date: 03/24/2009 22:26:51 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_OTGasto]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Lit_OTGasto]
GO
/****** Object:  Table [dbo].[Lit_OTMaterial]    Script Date: 03/24/2009 22:26:54 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_OTMaterial]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Lit_OTMaterial]
GO
/****** Object:  Table [dbo].[Lit_OTDetalle]    Script Date: 03/24/2009 22:26:50 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_OTDetalle]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Lit_OTDetalle]
GO
/****** Object:  Table [dbo].[Lit_Maquina]    Script Date: 03/24/2009 22:26:41 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_Maquina]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Lit_Maquina]
GO
/****** Object:  Table [dbo].[Lit_Operario]    Script Date: 03/24/2009 22:26:43 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_Operario]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Lit_Operario]
GO
/****** Object:  Table [dbo].[Lit_ParametrosBodega]    Script Date: 03/24/2009 22:26:55 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_ParametrosBodega]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Lit_ParametrosBodega]
GO
/****** Object:  Table [dbo].[Lit_Gasto]    Script Date: 03/24/2009 22:26:40 ******/
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_Gasto]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Lit_Gasto]
GO
/****** Object:  Table [dbo].[Lit_Gasto]    Script Date: 03/24/2009 22:26:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_Gasto]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Lit_Gasto](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[EmpresaId] [int] NOT NULL,
	[Concepto] [varchar](50) NOT NULL,
	[Monto] [money] NOT NULL,
	[Tipo] [char](1) NOT NULL,
	[Activo] [bit] NULL,
 CONSTRAINT [PK_Litografia_Gasto] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Lit_OrdenTrabajo]    Script Date: 03/24/2009 22:26:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_OrdenTrabajo]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Lit_OrdenTrabajo](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[EmpresaId] [int] NULL,
	[FechaInicial] [datetime] NULL,
	[FechaFinal] [datetime] NULL,
	[NumeroOT] [varchar](30) NULL,
	[ClienteId] [varchar](12) NULL,
	[ArticuloId] [varchar](13) NULL,
	[Unidades] [decimal](10, 2) NULL,
	[ManoObraIndirecta] [decimal](10, 2) NULL,
	[Estado] [char](1) NULL,
 CONSTRAINT [PK_Lit_RegistroOT] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Lit_Maquina]    Script Date: 03/24/2009 22:26:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_Maquina]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Lit_Maquina](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[EmpresaId] [int] NOT NULL,
	[Nombre] [varchar](100) NOT NULL,
	[CostoxHora] [money] NOT NULL,
 CONSTRAINT [PK_Lit_Maquina] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Lit_Puesto]    Script Date: 03/24/2009 22:26:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_Puesto]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Lit_Puesto](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Nombre] [varchar](50) NOT NULL,
	[Estado] [char](1) NOT NULL,
 CONSTRAINT [PK_Lit_Puesto] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Lit_ParametrosBodega]    Script Date: 03/24/2009 22:26:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_ParametrosBodega]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Lit_ParametrosBodega](
	[EmpresaId] [int] NOT NULL,
	[SucursalId] [int] NOT NULL,
	[BodegaMateriaPrima] [int] NOT NULL,
	[BodegaProductoEnProceso] [int] NOT NULL,
	[BodegaProductoTerminado] [int] NOT NULL,
 CONSTRAINT [PK_Lit_ParametrosBodega] PRIMARY KEY CLUSTERED 
(
	[EmpresaId] ASC,
	[SucursalId] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[lit_aplicacion]    Script Date: 03/24/2009 22:26:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_aplicacion]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[lit_aplicacion](
	[lit_aplicacion_id] [int] IDENTITY(1,1) NOT NULL,
	[lit_aplicacion_nombre] [varchar](50) NOT NULL,
	[lit_aplicacion_desc] [varchar](255) NOT NULL,
	[lit_empresa_id] [int] NOT NULL,
 CONSTRAINT [PK_lit_aplicacion] PRIMARY KEY CLUSTERED 
(
	[lit_aplicacion_id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Lit_OTMaterial]    Script Date: 03/24/2009 22:26:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_OTMaterial]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Lit_OTMaterial](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[OTId] [int] NULL,
	[Fecha] [datetime] NULL,
	[ArticuloId] [varchar](13) NULL,
	[Tipo] [char](1) NULL,
	[Cantidad] [decimal](10, 2) NULL,
	[OperarioId] [int] NULL,
	[Departamento] [varchar](100) NULL,
	[CostoArticuloUnitario] [money] NULL,
	[CostoArticuloTotal] [money] NULL,
 CONSTRAINT [PK_Lit_RegistroOTMaterial] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Lit_OTGasto]    Script Date: 03/24/2009 22:26:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_OTGasto]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Lit_OTGasto](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[OTId] [int] NULL,
	[GastoId] [int] NULL,
	[Monto] [decimal](10, 2) NULL,
 CONSTRAINT [PK_Lit_OTGasto] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[Lit_OTDetalle]    Script Date: 03/24/2009 22:26:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_OTDetalle]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Lit_OTDetalle](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[OTId] [int] NULL,
	[Fecha] [datetime] NULL,
	[OperarioId] [int] NULL,
	[AyudanteId] [int] NULL,
	[MaquinaId] [int] NULL,
	[Cantidad] [decimal](10, 2) NULL,
	[HorasRegular] [decimal](10, 2) NULL,
	[HorasExtra] [decimal](10, 2) NULL,
	[HorasDoble] [decimal](10, 2) NULL,
	[Tipo] [char](1) NULL,
	[Descripcion] [varchar](200) NULL,
	[CostoAyudantexHora] [money] NULL,
	[CostoOperarioxHora] [money] NULL,
	[CostoHorasRegular] [money] NULL,
	[CostoHorasExtra] [money] NULL,
	[CostoHorasDoble] [money] NULL,
	[CostoMaquinaxHora] [money] NULL,
	[CostoMaquina] [money] NULL,
 CONSTRAINT [PK_lit_registroOTDetalle] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Lit_Operario]    Script Date: 03/24/2009 22:26:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Lit_Operario]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Lit_Operario](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[EmpresaId] [int] NOT NULL,
	[Nombre] [varchar](200) NOT NULL,
	[PuestoId] [int] NOT NULL,
	[CostoxHora] [money] NOT NULL,
 CONSTRAINT [PK_Lit_Operario] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[lit_privilegio]    Script Date: 03/24/2009 22:26:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_privilegio]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[lit_privilegio](
	[lit_privilegio_id] [int] IDENTITY(1,1) NOT NULL,
	[lit_privilegio_nombre] [varchar](50) NOT NULL,
	[lit_privilegio_desc] [varchar](250) NOT NULL,
	[lit_privilegio_padre_id] [int] NULL,
	[lit_privilegio_tipo] [varchar](50) NOT NULL,
	[lit_aplicacion_id] [int] NOT NULL,
 CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED 
(
	[lit_privilegio_id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[lit_rol]    Script Date: 03/24/2009 22:27:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_rol]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[lit_rol](
	[lit_rol_id] [int] IDENTITY(1,1) NOT NULL,
	[lit_rol_nombre] [varchar](50) NOT NULL,
	[lit_rol_desc] [varchar](255) NOT NULL,
	[lit_aplicacion_id] [int] NOT NULL,
 CONSTRAINT [PK_lit_rol] PRIMARY KEY CLUSTERED 
(
	[lit_rol_id] ASC
) ON [PRIMARY],
 CONSTRAINT [UK_lit_rol] UNIQUE NONCLUSTERED 
(
	[lit_rol_nombre] ASC,
	[lit_aplicacion_id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[lit_usuario]    Script Date: 03/24/2009 22:27:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_usuario]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[lit_usuario](
	[lit_usuario_id] [int] IDENTITY(1,1) NOT NULL,
	[lit_usuario_username] [varchar](50) NOT NULL,
	[lit_usuario_password] [varchar](50) NOT NULL,
	[lit_usuario_nombre] [varchar](50) NULL,
	[lit_usuario_apellido] [varchar](50) NULL,
	[lit_aplicacion_id] [int] NOT NULL,
 CONSTRAINT [PK_lit_usuario] PRIMARY KEY CLUSTERED 
(
	[lit_usuario_id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[lit_rol_privilegio]    Script Date: 03/24/2009 22:27:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_rol_privilegio]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[lit_rol_privilegio](
	[lit_rol_id] [int] NOT NULL,
	[lit_privilegio_id] [int] NOT NULL,
 CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED 
(
	[lit_rol_id] ASC,
	[lit_privilegio_id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[lit_usuario_rol]    Script Date: 03/24/2009 22:27:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[lit_usuario_rol]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[lit_usuario_rol](
	[lit_usuario_id] [int] NOT NULL,
	[lit_rol_id] [int] NOT NULL,
 CONSTRAINT [PK_lit_usuario_rol] PRIMARY KEY CLUSTERED 
(
	[lit_usuario_id] ASC,
	[lit_rol_id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  ForeignKey [FK_Lit_Operario_Lit_Puesto]    Script Date: 03/24/2009 22:26:43 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Lit_Operario_Lit_Puesto]') AND type = 'F')
ALTER TABLE [dbo].[Lit_Operario]  WITH CHECK ADD  CONSTRAINT [FK_Lit_Operario_Lit_Puesto] FOREIGN KEY([PuestoId])
REFERENCES [dbo].[Lit_Puesto] ([Id])
GO
ALTER TABLE [dbo].[Lit_Operario] CHECK CONSTRAINT [FK_Lit_Operario_Lit_Puesto]
GO
/****** Object:  ForeignKey [FK_Lit_RegistroOT_Lit_RegistroOT]    Script Date: 03/24/2009 22:26:45 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Lit_RegistroOT_Lit_RegistroOT]') AND type = 'F')
ALTER TABLE [dbo].[Lit_OrdenTrabajo]  WITH CHECK ADD  CONSTRAINT [FK_Lit_RegistroOT_Lit_RegistroOT] FOREIGN KEY([Id])
REFERENCES [dbo].[Lit_OrdenTrabajo] ([Id])
GO
ALTER TABLE [dbo].[Lit_OrdenTrabajo] CHECK CONSTRAINT [FK_Lit_RegistroOT_Lit_RegistroOT]
GO
/****** Object:  ForeignKey [FK_lit_registroOTDetalle_Lit_RegistroOT]    Script Date: 03/24/2009 22:26:50 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_registroOTDetalle_Lit_RegistroOT]') AND type = 'F')
ALTER TABLE [dbo].[Lit_OTDetalle]  WITH CHECK ADD  CONSTRAINT [FK_lit_registroOTDetalle_Lit_RegistroOT] FOREIGN KEY([OTId])
REFERENCES [dbo].[Lit_OrdenTrabajo] ([Id])
GO
ALTER TABLE [dbo].[Lit_OTDetalle] CHECK CONSTRAINT [FK_lit_registroOTDetalle_Lit_RegistroOT]
GO
/****** Object:  ForeignKey [FK_Lit_OTGasto_Lit_Gasto]    Script Date: 03/24/2009 22:26:51 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Lit_OTGasto_Lit_Gasto]') AND type = 'F')
ALTER TABLE [dbo].[Lit_OTGasto]  WITH CHECK ADD  CONSTRAINT [FK_Lit_OTGasto_Lit_Gasto] FOREIGN KEY([GastoId])
REFERENCES [dbo].[Lit_Gasto] ([Id])
GO
ALTER TABLE [dbo].[Lit_OTGasto] CHECK CONSTRAINT [FK_Lit_OTGasto_Lit_Gasto]
GO
/****** Object:  ForeignKey [FK_Lit_OTGasto_Lit_OrdenTrabajo]    Script Date: 03/24/2009 22:26:52 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Lit_OTGasto_Lit_OrdenTrabajo]') AND type = 'F')
ALTER TABLE [dbo].[Lit_OTGasto]  WITH CHECK ADD  CONSTRAINT [FK_Lit_OTGasto_Lit_OrdenTrabajo] FOREIGN KEY([OTId])
REFERENCES [dbo].[Lit_OrdenTrabajo] ([Id])
GO
ALTER TABLE [dbo].[Lit_OTGasto] CHECK CONSTRAINT [FK_Lit_OTGasto_Lit_OrdenTrabajo]
GO
/****** Object:  ForeignKey [FK_lit_privilegio_lit_aplicacion]    Script Date: 03/24/2009 22:26:57 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_privilegio_lit_aplicacion]') AND type = 'F')
ALTER TABLE [dbo].[lit_privilegio]  WITH CHECK ADD  CONSTRAINT [FK_lit_privilegio_lit_aplicacion] FOREIGN KEY([lit_aplicacion_id])
REFERENCES [dbo].[lit_aplicacion] ([lit_aplicacion_id])
GO
ALTER TABLE [dbo].[lit_privilegio] CHECK CONSTRAINT [FK_lit_privilegio_lit_aplicacion]
GO
/****** Object:  ForeignKey [FK_lit_privilegio_lit_privilegio]    Script Date: 03/24/2009 22:26:57 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_privilegio_lit_privilegio]') AND type = 'F')
ALTER TABLE [dbo].[lit_privilegio]  WITH CHECK ADD  CONSTRAINT [FK_lit_privilegio_lit_privilegio] FOREIGN KEY([lit_privilegio_padre_id])
REFERENCES [dbo].[lit_privilegio] ([lit_privilegio_id])
GO
ALTER TABLE [dbo].[lit_privilegio] CHECK CONSTRAINT [FK_lit_privilegio_lit_privilegio]
GO
/****** Object:  ForeignKey [FK_lit_rol_lit_aplicacion]    Script Date: 03/24/2009 22:27:00 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_rol_lit_aplicacion]') AND type = 'F')
ALTER TABLE [dbo].[lit_rol]  WITH CHECK ADD  CONSTRAINT [FK_lit_rol_lit_aplicacion] FOREIGN KEY([lit_aplicacion_id])
REFERENCES [dbo].[lit_aplicacion] ([lit_aplicacion_id])
GO
ALTER TABLE [dbo].[lit_rol] CHECK CONSTRAINT [FK_lit_rol_lit_aplicacion]
GO
/****** Object:  ForeignKey [FK_lit_rol_privilegio_lit_privilegio]    Script Date: 03/24/2009 22:27:01 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_rol_privilegio_lit_privilegio]') AND type = 'F')
ALTER TABLE [dbo].[lit_rol_privilegio]  WITH CHECK ADD  CONSTRAINT [FK_lit_rol_privilegio_lit_privilegio] FOREIGN KEY([lit_privilegio_id])
REFERENCES [dbo].[lit_privilegio] ([lit_privilegio_id])
GO
ALTER TABLE [dbo].[lit_rol_privilegio] CHECK CONSTRAINT [FK_lit_rol_privilegio_lit_privilegio]
GO
/****** Object:  ForeignKey [FK_lit_rol_privilegio_lit_rol]    Script Date: 03/24/2009 22:27:01 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_rol_privilegio_lit_rol]') AND type = 'F')
ALTER TABLE [dbo].[lit_rol_privilegio]  WITH CHECK ADD  CONSTRAINT [FK_lit_rol_privilegio_lit_rol] FOREIGN KEY([lit_rol_id])
REFERENCES [dbo].[lit_rol] ([lit_rol_id])
GO
ALTER TABLE [dbo].[lit_rol_privilegio] CHECK CONSTRAINT [FK_lit_rol_privilegio_lit_rol]
GO
/****** Object:  ForeignKey [FK_lit_usuario_lit_aplicacion]    Script Date: 03/24/2009 22:27:03 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_usuario_lit_aplicacion]') AND type = 'F')
ALTER TABLE [dbo].[lit_usuario]  WITH CHECK ADD  CONSTRAINT [FK_lit_usuario_lit_aplicacion] FOREIGN KEY([lit_aplicacion_id])
REFERENCES [dbo].[lit_aplicacion] ([lit_aplicacion_id])
GO
ALTER TABLE [dbo].[lit_usuario] CHECK CONSTRAINT [FK_lit_usuario_lit_aplicacion]
GO
/****** Object:  ForeignKey [FK_lit_usuario_lit_usuario]    Script Date: 03/24/2009 22:27:03 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_usuario_lit_usuario]') AND type = 'F')
ALTER TABLE [dbo].[lit_usuario]  WITH CHECK ADD  CONSTRAINT [FK_lit_usuario_lit_usuario] FOREIGN KEY([lit_usuario_id])
REFERENCES [dbo].[lit_usuario] ([lit_usuario_id])
GO
ALTER TABLE [dbo].[lit_usuario] CHECK CONSTRAINT [FK_lit_usuario_lit_usuario]
GO
/****** Object:  ForeignKey [FK_lit_usuario_rol_lit_rol]    Script Date: 03/24/2009 22:27:04 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_usuario_rol_lit_rol]') AND type = 'F')
ALTER TABLE [dbo].[lit_usuario_rol]  WITH CHECK ADD  CONSTRAINT [FK_lit_usuario_rol_lit_rol] FOREIGN KEY([lit_rol_id])
REFERENCES [dbo].[lit_rol] ([lit_rol_id])
GO
ALTER TABLE [dbo].[lit_usuario_rol] CHECK CONSTRAINT [FK_lit_usuario_rol_lit_rol]
GO
/****** Object:  ForeignKey [FK_lit_usuario_rol_lit_usuario]    Script Date: 03/24/2009 22:27:04 ******/
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_lit_usuario_rol_lit_usuario]') AND type = 'F')
ALTER TABLE [dbo].[lit_usuario_rol]  WITH CHECK ADD  CONSTRAINT [FK_lit_usuario_rol_lit_usuario] FOREIGN KEY([lit_usuario_id])
REFERENCES [dbo].[lit_usuario] ([lit_usuario_id])
GO
ALTER TABLE [dbo].[lit_usuario_rol] CHECK CONSTRAINT [FK_lit_usuario_rol_lit_usuario]
GO
